/********************************************************************
FileName    :   Dal_zwcl_khyszzH.cs
CreateTime  :   2015-09-18 12:09
BaseClass   :   Dal_zwcl_khyszzH
FileType    :   .cs
Author      :  minjie
Description :   Dal_zwcl_khyszzHDAL层（简单三层）
*********************************************************************/

using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;

using System.Data;
namespace OS.DAL
{
	/// <summary>
	/// Dal_zwcl_khyszzH的摘要说明。
	/// </summary>
	public partial class Dal_zwcl_khyszzH 
  	{ 
     		      
  		public bool Exists(int DjLsh) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select count(1) from zwcl_khyszzH"); 
  			strSql.Append(" where "); 
           SqlParameter[] parameters = { new SqlParameter("@DjLsh", SqlDbType.Int,4)};  
  			return DbHelperSQL.Exists(strSql.ToString(),parameters); 
  		} 
  		 
  				 
  		 
  		/// <summary> 
  		/// 增加一条数据 
  		/// </summary> 
  		public  bool  Add(zwcl_khyszzH_Entity model) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("insert into zwcl_khyszzH(");			 
  	strSql.Append("DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,yy,mm,khbh,khmc,bmmc,qcwsk,bqysk,bqyisk,tzje,bqwsk) values ("); 
  	strSql.Append("	@DjLsh,@DjBtZdh,@DjFtZdh,@DjStZdh,@DjState,@DjCount,@yy,@mm,@khbh,@khmc,@bmmc,@qcwsk,@bqysk,@bqyisk,@tzje,@bqwsk	 ) "); 
  			SqlParameter[] parameters = { 
              new SqlParameter("@DjLsh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjBtZdh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjFtZdh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjStZdh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjState", SqlDbType.Char,10) ,              
              new SqlParameter("@DjCount", SqlDbType.Int,4) ,              
              new SqlParameter("@yy", SqlDbType.Int,4) ,              
              new SqlParameter("@mm", SqlDbType.Int,4) ,              
              new SqlParameter("@khbh", SqlDbType.VarChar,50) ,              
              new SqlParameter("@khmc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@bmmc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@qcwsk", SqlDbType.Decimal,9) ,              
              new SqlParameter("@bqysk", SqlDbType.Decimal,9) ,              
              new SqlParameter("@bqyisk", SqlDbType.Decimal,9) ,              
              new SqlParameter("@tzje", SqlDbType.Decimal,9) ,              
              new SqlParameter("@bqwsk", SqlDbType.Decimal,9)};             
              parameters[0].Value = model.DjLsh;  
              
              parameters[1].Value = model.DjBtZdh;  
              
              parameters[2].Value = model.DjFtZdh;  
              
              parameters[3].Value = model.DjStZdh;  
              
           if (model.DjState != null)  
              parameters[4].Value = model.DjState;  
           else  
              parameters[4].Value = DBNull.Value;  
              
              parameters[5].Value = model.DjCount;  
              
              parameters[6].Value = model.yy;  
              
              parameters[7].Value = model.mm;  
              
           if (model.khbh != null)  
              parameters[8].Value = model.khbh;  
           else  
              parameters[8].Value = DBNull.Value;  
              
           if (model.khmc != null)  
              parameters[9].Value = model.khmc;  
           else  
              parameters[9].Value = DBNull.Value;  
              
           if (model.bmmc != null)  
              parameters[10].Value = model.bmmc;  
           else  
              parameters[10].Value = DBNull.Value;  
              
           if (model.qcwsk != null)  
              parameters[11].Value = model.qcwsk;  
           else  
              parameters[11].Value = DBNull.Value;  
              
           if (model.bqysk != null)  
              parameters[12].Value = model.bqysk;  
           else  
              parameters[12].Value = DBNull.Value;  
              
           if (model.bqyisk != null)  
              parameters[13].Value = model.bqyisk;  
           else  
              parameters[13].Value = DBNull.Value;  
              
           if (model.tzje != null)  
              parameters[14].Value = model.tzje;  
           else  
              parameters[14].Value = DBNull.Value;  
              
           if (model.bqwsk != null)  
              parameters[15].Value = model.bqwsk;  
           else  
              parameters[15].Value = DBNull.Value;  
              
  			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);			 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
              return false;; 
           }  
  		} 
  		 
  		/// <summary> 
  		/// 增加一条数据(字符串) 
  		/// </summary> 
  		public  string  AddStr(zwcl_khyszzH_Entity model) 
  		{ 
  				if(model.DjLsh==null) 
  				{ 
  					model.DjLsh=0; 
  				} 
  				if(model.DjBtZdh==null) 
  				{ 
  					model.DjBtZdh=0; 
  				} 
  				if(model.DjFtZdh==null) 
  				{ 
  					model.DjFtZdh=0; 
  				} 
  				if(model.DjStZdh==null) 
  				{ 
  					model.DjStZdh=0; 
  				} 
  				if(model.DjState==null) 
  				{ 
  					model.DjState="";  
  				} 
  				if(model.DjCount==null) 
  				{ 
  					model.DjCount=0; 
  				} 
  				if(model.yy==null) 
  				{ 
  					model.yy=0; 
  				} 
  				if(model.mm==null) 
  				{ 
  					model.mm=0; 
  				} 
  				if(model.khbh==null) 
  				{ 
  					model.khbh="";  
  				} 
  				if(model.khmc==null) 
  				{ 
  					model.khmc="";  
  				} 
  				if(model.bmmc==null) 
  				{ 
  					model.bmmc="";  
  				} 
  				if(model.qcwsk==null) 
  				{ 
  					model.qcwsk=0; 
  				} 
  				if(model.bqysk==null) 
  				{ 
  					model.bqysk=0; 
  				} 
  				if(model.bqyisk==null) 
  				{ 
  					model.bqyisk=0; 
  				} 
  				if(model.tzje==null) 
  				{ 
  					model.tzje=0; 
  				} 
  				if(model.bqwsk==null) 
  				{ 
  					model.bqwsk=0; 
  				} 
  		 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("insert into zwcl_khyszzH(");			 
  	strSql.Append("DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,yy,mm,khbh,khmc,bmmc,qcwsk,bqysk,bqyisk,tzje,bqwsk) values ("); 
  	strSql.Append("	"+ model.DjLsh+","+ model.DjBtZdh+","+ model.DjFtZdh+","+ model.DjStZdh+",'"+ model.DjState+"',"+ model.DjCount+","+ model.yy+","+ model.mm+",'"+ model.khbh+"','"+ model.khmc+"','"+ model.bmmc+"',"+ model.qcwsk+","+ model.bqysk+","+ model.bqyisk+","+ model.tzje+"," +model.bqwsk+"	 ) "); 
           return strSql.ToString(); 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 更新一条数据 
  		/// </summary> 
  		public bool Update(zwcl_khyszzH_Entity model) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("update zwcl_khyszzH set "); 
              strSql.Append(" DjLsh = @DjLsh,"); 
              strSql.Append(" DjBtZdh = @DjBtZdh,"); 
              strSql.Append(" DjFtZdh = @DjFtZdh,"); 
              strSql.Append(" DjStZdh = @DjStZdh,"); 
              strSql.Append(" DjState = @DjState,"); 
              strSql.Append(" DjCount = @DjCount,"); 
              strSql.Append(" yy = @yy,"); 
              strSql.Append(" mm = @mm,"); 
              strSql.Append(" khbh = @khbh,"); 
              strSql.Append(" khmc = @khmc,"); 
              strSql.Append(" bmmc = @bmmc,"); 
              strSql.Append(" qcwsk = @qcwsk,"); 
              strSql.Append(" bqysk = @bqysk,"); 
              strSql.Append(" bqyisk = @bqyisk,"); 
              strSql.Append(" tzje = @tzje,"); 
              strSql.Append(" bqwsk = @bqwsk"); 
  			strSql.Append(" where  DjLsh=@DjLsh "); 
  						 
  SqlParameter[] parameters = { 
              new SqlParameter("@DjLsh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjBtZdh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjFtZdh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjStZdh", SqlDbType.Int,4) ,              
              new SqlParameter("@DjState", SqlDbType.Char,10) ,              
              new SqlParameter("@DjCount", SqlDbType.Int,4) ,              
              new SqlParameter("@yy", SqlDbType.Int,4) ,              
              new SqlParameter("@mm", SqlDbType.Int,4) ,              
              new SqlParameter("@khbh", SqlDbType.VarChar,50) ,              
              new SqlParameter("@khmc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@bmmc", SqlDbType.VarChar,50) ,              
              new SqlParameter("@qcwsk", SqlDbType.Decimal,9) ,              
              new SqlParameter("@bqysk", SqlDbType.Decimal,9) ,              
              new SqlParameter("@bqyisk", SqlDbType.Decimal,9) ,              
              new SqlParameter("@tzje", SqlDbType.Decimal,9) ,              
              new SqlParameter("@bqwsk", SqlDbType.Decimal,9)};             
              parameters[0].Value = model.DjLsh;  
              
              parameters[1].Value = model.DjBtZdh;  
              
              parameters[2].Value = model.DjFtZdh;  
              
              parameters[3].Value = model.DjStZdh;  
              
           if (model.DjState != null)  
              parameters[4].Value = model.DjState;  
           else  
              parameters[4].Value = DBNull.Value;  
              
              parameters[5].Value = model.DjCount;  
              
              parameters[6].Value = model.yy;  
              
              parameters[7].Value = model.mm;  
              
           if (model.khbh != null)  
              parameters[8].Value = model.khbh;  
           else  
              parameters[8].Value = DBNull.Value;  
              
           if (model.khmc != null)  
              parameters[9].Value = model.khmc;  
           else  
              parameters[9].Value = DBNull.Value;  
              
           if (model.bmmc != null)  
              parameters[10].Value = model.bmmc;  
           else  
              parameters[10].Value = DBNull.Value;  
              
           if (model.qcwsk != null)  
              parameters[11].Value = model.qcwsk;  
           else  
              parameters[11].Value = DBNull.Value;  
              
           if (model.bqysk != null)  
              parameters[12].Value = model.bqysk;  
           else  
              parameters[12].Value = DBNull.Value;  
              
           if (model.bqyisk != null)  
              parameters[13].Value = model.bqyisk;  
           else  
              parameters[13].Value = DBNull.Value;  
              
           if (model.tzje != null)  
              parameters[14].Value = model.tzje;  
           else  
              parameters[14].Value = DBNull.Value;  
              
           if (model.bqwsk != null)  
              parameters[15].Value = model.bqwsk;  
           else  
              parameters[15].Value = DBNull.Value;  
              
              int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
  				return false; 
  			} 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 删除一条数据 
  		/// </summary> 
  		public bool Delete(int  DjLsh) 
  		{ 
  			 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("delete from zwcl_khyszzH "); 
  			strSql.Append(" where  DjLsh=@DjLsh"); 
  			SqlParameter[] parameters = {  new SqlParameter("@DjLsh", SqlDbType.Int,4) };  
    parameters[0].Value = DjLsh;  
   
  			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
  				return false; 
  			} 
  		} 
  		 
  		/// <summary> 
  		/// 批量删除一批数据 
  		/// </summary> 
  		public bool DeleteList(string DjLshlist ) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("delete from zwcl_khyszzH "); 
  			strSql.Append(" where ID in ("+DjLshlist + ")  "); 
  			int rows=DbHelperSQL.ExecuteSql(strSql.ToString()); 
  			if (rows > 0) 
  			{ 
  				return true; 
  			} 
  			else 
  			{ 
  				return false; 
  			} 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 得到一个对象实体 
  		/// </summary> 
  		public zwcl_khyszzH_Entity GetModel(int   DjLsh) 
  		{ 
  			 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select  DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,yy,mm,khbh,khmc,bmmc,qcwsk,bqysk,bqyisk,tzje,bqwsk");	
		strSql.Append("  from zwcl_khyszzH"); 
  			strSql.Append(" where  DjLsh=@DjLsh "); 
  			SqlParameter[] parameters = {  new SqlParameter("@DjLsh", SqlDbType.Int,4) };  
    parameters[0].Value = DjLsh;  
  			 
  			zwcl_khyszzH_Entity model=new zwcl_khyszzH_Entity(); 
  			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); 
  			 
  			if(ds!=null&&ds.Tables[0].Rows.Count>0) 
  			{ 
  		DataTable dt=ds.Tables[0];	  
  				if(dt.Rows[0]["DjLsh"]!=null&&dt.Rows[0]["DjLsh"].ToString()!="") 
  				{ 
  					model.DjLsh=int.Parse(dt.Rows[0]["DjLsh"].ToString()); 
  				} 
  				if(dt.Rows[0]["DjBtZdh"]!=null&&dt.Rows[0]["DjBtZdh"].ToString()!="") 
  				{ 
  					model.DjBtZdh=int.Parse(dt.Rows[0]["DjBtZdh"].ToString()); 
  				} 
  				if(dt.Rows[0]["DjFtZdh"]!=null&&dt.Rows[0]["DjFtZdh"].ToString()!="") 
  				{ 
  					model.DjFtZdh=int.Parse(dt.Rows[0]["DjFtZdh"].ToString()); 
  				} 
  				if(dt.Rows[0]["DjStZdh"]!=null&&dt.Rows[0]["DjStZdh"].ToString()!="") 
  				{ 
  					model.DjStZdh=int.Parse(dt.Rows[0]["DjStZdh"].ToString()); 
  				} 
  				model.DjState= dt.Rows[0]["DjState"].ToString(); 
  				if(dt.Rows[0]["DjCount"]!=null&&dt.Rows[0]["DjCount"].ToString()!="") 
  				{ 
  					model.DjCount=int.Parse(dt.Rows[0]["DjCount"].ToString()); 
  				} 
  				if(dt.Rows[0]["yy"]!=null&&dt.Rows[0]["yy"].ToString()!="") 
  				{ 
  					model.yy=int.Parse(dt.Rows[0]["yy"].ToString()); 
  				} 
  				if(dt.Rows[0]["mm"]!=null&&dt.Rows[0]["mm"].ToString()!="") 
  				{ 
  					model.mm=int.Parse(dt.Rows[0]["mm"].ToString()); 
  				} 
  				model.khbh= dt.Rows[0]["khbh"].ToString(); 
  				model.khmc= dt.Rows[0]["khmc"].ToString(); 
  				model.bmmc= dt.Rows[0]["bmmc"].ToString(); 
  				if(dt.Rows[0]["qcwsk"]!=null&&dt.Rows[0]["qcwsk"].ToString()!="") 
  				{ 
  					model.qcwsk=decimal.Parse(dt.Rows[0]["qcwsk"].ToString()); 
  				} 
  				if(dt.Rows[0]["bqysk"]!=null&&dt.Rows[0]["bqysk"].ToString()!="") 
  				{ 
  					model.bqysk=decimal.Parse(dt.Rows[0]["bqysk"].ToString()); 
  				} 
  				if(dt.Rows[0]["bqyisk"]!=null&&dt.Rows[0]["bqyisk"].ToString()!="") 
  				{ 
  					model.bqyisk=decimal.Parse(dt.Rows[0]["bqyisk"].ToString()); 
  				} 
  				if(dt.Rows[0]["tzje"]!=null&&dt.Rows[0]["tzje"].ToString()!="") 
  				{ 
  					model.tzje=decimal.Parse(dt.Rows[0]["tzje"].ToString()); 
  				} 
  				if(dt.Rows[0]["bqwsk"]!=null&&dt.Rows[0]["bqwsk"].ToString()!="") 
  				{ 
  					model.bqwsk=decimal.Parse(dt.Rows[0]["bqwsk"].ToString()); 
  				} 
  				return model; 
  			} 
  			else 
  			{ 
  				return null; 
  			} 
  		} 
  		 
  		/// <summary> 
  		/// 分页获取数据列表 
  		/// </summary> 
  		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  		 strSql.Append("SELECT * FROM ( "); 
  		 strSql.Append(" SELECT ROW_NUMBER() OVER ("); 
  if (!string.IsNullOrEmpty(orderby.Trim())) 
 { 
    strSql.Append("order by T." + orderby); 
 } 
else  
 { 
     strSql.Append("order by T.DjLsh desc"); 
 } 
		 strSql.Append(")AS Row, T.*  from zwcl_khyszzH T "); 
  		 if (!string.IsNullOrEmpty(strWhere.Trim()))  
  			{ 
  			 strSql.Append(" WHERE " + strWhere); 
  			} 
  		    strSql.Append(" ) TT"); 
  	        strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);			return DbHelperSQL.Query(strSql.ToString()); 
  		} 
  		 
  		 
  		/// <summary> 
  		/// 获得数据列表 
  		/// </summary> 
  		public DataSet GetList(string strWhere) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select * "); 
  			strSql.Append(" FROM zwcl_khyszzH "); 
  			if(strWhere.Trim()!="") 
  			{ 
  				strSql.Append(" where "+strWhere); 
  			} 
  			return DbHelperSQL.Query(strSql.ToString()); 
  		} 
  		 
  		/// <summary> 
  		/// 获得前几行数据 
  		/// </summary> 
  		public DataSet GetList(int Top,string strWhere,string filedOrder) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select "); 
  			if(Top>0) 
  			{ 
  				strSql.Append(" top "+Top.ToString()); 
  			} 
  			strSql.Append(" * "); 
  			strSql.Append(" FROM zwcl_khyszzH "); 
  			if(strWhere.Trim()!="") 
  			{ 
  				strSql.Append(" where "+strWhere); 
  			} 
  			strSql.Append(" order by " + filedOrder); 
  			return DbHelperSQL.Query(strSql.ToString()); 
  		} 
  		 
  		/// <summary> 
  		/// 获得记录条数 
  		/// </summary> 
  		public int GetRecordCount(string strWhere) 
  		{ 
  			StringBuilder strSql=new StringBuilder(); 
  			strSql.Append("select count(1) "); 
  			strSql.Append(" FROM zwcl_khyszzH "); 
  			if(strWhere.Trim()!="") 
  			{ 
  				strSql.Append(" where "+strWhere); 
  			} 
  		   object obj=	DbHelperSQL.GetSingle(strSql.ToString()); 
  			if(obj!=null && obj.ToString()!="") 
  			{ 
              	return Convert.ToInt32(obj); 
  			} 
  			else 
  			return 0; 
  		} 
   
      
  	} 
  
}
